class Bullet extends CollidableSprite{
  
  num bulletSpeed = 4;
  bool destroyed = false;
  Sound sound;
  
  Bullet():super({'src':'img/bullet.png'})
  {
    sound = new Sound('sfx/lasershot.ogg');
  }
  
  void onNewParent()
  {
    super.onNewParent();
    sound.play();
  }
  
  void collisionDetected()
  {
    this.destroyed = true;
  }
    
  void update(int time)
  {
    if(this.destroyed) 
    {
      this.destroy();
    } 
    else 
    {
      this.incX(bulletSpeed);
    
      if(this.getX() > parent.width)
      {
        this.destroy();
      }
    }
  }
  
  void destroy()
  {
    colManager.removeObject(this);
    parent.removeChild(this);
    this.parent = null;
  }
  
  String getType()
  {
    return "BULLET";
  }
  
  List<String> getCollidableTypes()
  {
    return ["ENEMY_SHIP"]; 
  }
}
